import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';

class StateValueBuilderView extends StatelessWidget {
  const StateValueBuilderView({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Center(
          child: ValueBuilder<int?>(
            builder: (value, updateFn) => Column(
              children: [
                Text("count -> " + value.toString()),
                ElevatedButton(
                  onPressed: () {
                    updateFn(value! + 1);
                  },
                  child: Text('ValueBuilder -> add'),
                )
              ],
            ),
            initialValue: 10,
            onDispose: () {},
            onUpdate: (value) {},
          ),
        )
      ],
    );
  }

  Widget _buildValueBuilder() {
    return ValueBuilder<bool?>(
      initialValue: false,
      builder: (value, update) =>
          Switch(value: value!, onChanged: (flag) => update(flag)),
      onUpdate: (value) => print("Value updated: $value"),
      onDispose: () => print("Widget unmounted"),
    );
  }



}
